package com.peng.greed;

/**
 * 能开的最大会议数
 */
public class Test02_MaxMeetingCount {

    /**
     * @param meetings 可以排的所有会议
     * @param done     可以开完的总会议个数
     * @param timeLine 时间线来到timeLine
     * @return
     */
    public int getMaxMeetingCount(Meeting[] meetings, int done, int timeLine) {
        if (meetings.length == 0) {
            return done;
        }

        int max = done;

        for (Meeting meeting : meetings) {
            if (meeting.start >= timeLine) {
                Meeting[] otherMeetings = copyButExcept(meetings, meeting);
                max = Math.max(max, getMaxMeetingCount(otherMeetings, done + 1, meeting.end));
            }
        }

        return max;


    }

    public Meeting[] copyButExcept(Meeting[] meetings, Meeting except) {
        Meeting[] dest = new Meeting[meetings.length - 1];
        int i = 0;
        for (Meeting meeting : meetings) {
            if (except != meeting) {
                dest[i++] = meeting;
            }
        }

        return dest;

    }

    static class Meeting {
        int start;
        int end;

        public Meeting(int start, int end) {
            this.start = start;
            this.end = end;
        }

    }


}
